package kr.hkit.androidcomplete01.chapter09;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Button;

public class MenuEditEx extends Activity {
	String TAG ="MenuEditEx";
	Button mBtn;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.d(TAG, "oncreate()");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch09_menuedit);
		mBtn = (Button) findViewById(R.id.ch09_menueditex_btn);
		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		Log.d(TAG, "onCreateOptionsMenu()");
		super.onCreateOptionsMenu(menu);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menuedit, menu);
		return true;
	}
	
	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		Log.d(TAG, "onPrepareOptionsMenu()");
		if(mBtn.getTextSize()==40){
			menu.findItem(R.id.ch09_menuedit_bigfont).setChecked(true);
		}else{
			menu.findItem(R.id.ch09_menuedit_bigfont).setChecked(false);
		}
		int color = mBtn.getTextColors().getDefaultColor();
		if(color == Color.RED){
			menu.findItem(R.id.ch09_menueidit_red).setChecked(true);
		}
		if(color == Color.GREEN){
			menu.findItem(R.id.ch09_menueidit_green).setChecked(true);
		}
		if(color == Color.BLUE){
			menu.findItem(R.id.ch09_menueidit_blue).setChecked(true);
		}
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Log.d(TAG, "onOptionsItemSelected()");
		switch(item.getItemId()){
		case R.id.ch09_menuedit_bigfont:
			if(item.isChecked()){
				mBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, 20);
			}
			else{
				mBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, 40);
			}
			return true;
		case R.id.ch09_menueidit_red:
			mBtn.setTextColor(Color.RED);
			break;
		case R.id.ch09_menueidit_green:
			mBtn.setTextColor(Color.GREEN);
			break;
		case R.id.ch09_menueidit_blue:
			mBtn.setTextColor(Color.BLUE);
			break;
		}
		return true;
	}
}
